package com.yulongtian.weekCompetition.month202301.week02;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * 可
 *
 * @author yulongTian
 * @create 2023-01-08 10:34
 */
public class Test02 {
    public static void main(String[] args) {
        int[] nums = {881784984, 829998714, 730002802, 56524562, 120336848, 548306998, 801116106, 828640251, 519131180, 819176153, 476262254, 15904939, 540793851, 53572296, 259044378, 491129827, 561147559, 205793082, 967833729};
        int k = 16;
        System.out.println(maxKelements(nums, k));
    }

    public static long maxKelements(int[] nums, int k) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });

        for (int num : nums) {
            priorityQueue.add(num);
        }

        long ans = 0L;
        for (int i = 0; i < k; i++) {
            int tempMax = priorityQueue.poll();
            ans += tempMax;
            priorityQueue.add(tempMax / 3 + (tempMax % 3 != 0 ? 1 : 0));
            priorityQueue.comparator();
        }

        return ans;
    }


}
